package com.mengzhilan.base;

/**
 * Description: 可权重排序接口
 * <br/>date: 2023/11/28 10:52
 *
 * @version 1.0
 * @author: xlp
 */
public interface WeightSortable<T extends WeightSortable<? super T>> extends Comparable<T>{
    /**
     * 设置权重
     * @param weight
     */
    void setWeight(int weight);

    /**
     * 获取权重
     * @return 获取权重值，默认返回0
     */
    default int getWeight(){
        return 0;
    }


    /**
     * 排序实现函数
     * @param o
     * @return
     */
    default int compareTo(T o) {
        if (o == null || this.getWeight() > o.getWeight()) return 1;
        return this.getWeight() == o.getWeight() ? 0 : -1;
    }
}
